define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'call/record/index',
                    add_url: 'call/record/add',
                    //edit_url: 'call/record/edit',
                    del_url: 'call/record/del',
                    //multi_url: 'call/record/multi',
                    table: 'call_record',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showExport: true,
                exportTypes: ['excel'],
                showColumns: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        /*{field: 'admin_id', title: __('Admin_id')},*/
                        {field: 'admin.nickname', title: __('Admin_id'), formatter: Table.api.formatter.label, visible: requirejs.s.contexts._.config.config.admined },
                        {field: 'task_name', title: __('所属任务')},
                        /*{field: 'type', title: __('Type'), visible:false, searchList: {"callin":__('type callin'),"callout":__('type callout'),"missed":__('type missed'),"answered":__('type answered'),"failed":__('type failed')}},*/
                        {field: 'type', title: __('Type'), operate:false, formatter: Table.api.formatter.flag, custom: { callin: 'warning', callout: 'info', answered: 'success', missed: 'default', failed: 'danger'}},
                        {field: 'caller_name', title: __('Caller_name')},
                        {field: 'caller_number', title: __('Caller_number')},
                        {field: 'gateway', title: __('Gateway'), formatter: Table.api.formatter.label},
                        {field: 'callee_number', title: __('Callee_number')},
                        {field: 'start_stamp', title: __('Start_stamp'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'answer_stamp', title: __('Answer_stamp'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'end_stamp', title: __('End_stamp'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'duration', title: __('Duration')},
                        {field: 'billsec', title: __('Billsec')},
/*
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
*/
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]//,
                //clickToSelect: false
            }
            );

            // 为表格绑定事件
            Table.api.bindevent(table);

            window.top.refreshCallRecord = function() {
                $('#toolbar .btn-refresh').click();
            };

        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
